#include <iostream>
#include <string>
#include <vector>
#include <map>
using namespace std;

typedef pair<string,int> psi;

int N,M;
vector<psi> vpsi,hvpsi;
map<string,int> name;

int main(){
    cin >> N >> M;
    for(int i = 0;i < N;i++){
        string str;
        cin >> str;
        vpsi.push_back({str,str.size()});
        for(int j = 0;j < i;j++){
        	psi p1 = vpsi[j];
        	string s;
        	for(int k = 1;k <= 16 - p1.second - str.size();k++){
        		s += '_';
        		name[str + s + p1.first] = k;
			}
		}
    }
    while(M--){
    	string str;
        cin >> str;
        hvpsi.push_back({str,str.size()});
	}
	
    return 0;
}
